package edu.zzuli.model.core;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import edu.zzuli.common.Visit;
import edu.zzuli.model.core.iface.PublicFacade;
import edu.zzuli.util.SpringBeanUtil;

/**
 * @author tianshaojie
 * @date 2011-8-14
 * @discription : 
 */
@Controller
public class LogoutAction {
	
	@Resource
	private PublicFacade publicFacade;
	
	Log log = LogFactory.getLog(this.getClass());
	
	public String execute() {
		try {
//			ActionContext.getContext().getSession().remove("myVisit");
//			ActionContext.getContext().getSession().remove(Constants_core.LOGIN_IP);
//			ActionContext.getContext().getSession().remove("xtgnList");
			Visit myVisit = (Visit) ActionContext.getContext().getSession().get("myVisit");
			System.err.println("=================" + myVisit.getCzy().getDlh());
			try {
				Map mapPara = new HashMap();
				mapPara.put("SFDL", 0);
				mapPara.put("ID", myVisit.getCzy().getId());
				getPublicFacade().execute("update gg_czyb set sfdl=:SFDL where id=:ID",mapPara);
			} catch (Exception e) {
				e.printStackTrace();
			}
			ActionContext.getContext().getSession().clear();
			ServletActionContext.getRequest ().getSession().invalidate();	
			return "success";
		} catch (Exception e) {
			return "error";
		}
	}
	
	private PublicFacade getPublicFacade() {
		return (PublicFacade) SpringBeanUtil.getBean("publicFacade");
	}
}
